package v1alpha1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type SystemdChaosSpec struct {
	// ContainerSelector specifies the target for injection
	ContainerSelector `json:",inline"`

	// Duration represents the duration of the chaos
	// +optional
	Duration *string `json:"duration,omitempty"`

	// Action 取值范围 stop
	Action SystemdAction `json:"action"`

	// Service 停止的服务名
	// +optional
	Service string `json:"service"`

	// RemoteCluster represents the remote cluster where the chaos will be deployed
	// +optional
	RemoteCluster string `json:"remoteCluster,omitempty"`
}

type SystemdAction string

// stop

const (
	SystemdActionStop SystemdAction = "stop"
)

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="action",type=string,JSONPath=`.spec.action`
// +kubebuilder:printcolumn:name="duration",type=string,JSONPath=`.spec.duration`
// +chaos-mesh:experiment

type SystemdChaos struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   SystemdChaosSpec           `json:"spec"`
	Status BladeOnlyCreateChaosStatus `json:"status,omitempty"`
}

var _ InnerObjectWithCustomStatus = (*SystemdChaos)(nil)
var _ InnerObjectWithSelector = (*SystemdChaos)(nil)
var _ InnerObject = (*SystemdChaos)(nil)

func init() {
	SchemeBuilder.Register(&SystemdChaos{}, &SystemdChaosList{})
}

// GetSelectorSpecs is a getter for selectors
func (obj *SystemdChaos) GetSelectorSpecs() map[string]interface{} {
	return map[string]interface{}{
		".": &obj.Spec.ContainerSelector,
	}
}

func (obj *SystemdChaos) GetCustomStatus() interface{} {
	return &obj.Status.BladeOnlyCreateChaosCustomStatus
}
